package com.hctforgreen.greenservice.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 首次安装 存储Util
 * 
 * @author Tallen Zhai
 * 
 */
public class LoginInStoreUtil {

	// ==================
	// 是否初次安装
	// ==================
	public static void saveFirstInstall(Activity activity, boolean bFirstInstall) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.IS_FIRST_INSTALL_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		Editor editor = sharedPreferences.edit();

		editor.putBoolean(HctConstants.IS_FIRST_INSTALL_STORE_KEY_VALUE,
				bFirstInstall);
		editor.apply();
	}

	public static boolean isFirstInstall(Activity activity) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.IS_FIRST_INSTALL_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		boolean bFirstInstall = sharedPreferences.getBoolean(
				HctConstants.IS_FIRST_INSTALL_STORE_KEY_VALUE, true);
		return bFirstInstall;
	}

	// ==================
	// 是否自动登录
	// ==================
	public static boolean isAutoLoginIn(Activity activity) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.IS_AUTO_LOGIN_IN_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		
		boolean bAutoLoginIn = sharedPreferences.getBoolean(
				HctConstants.IS_AUTO_LOGIN_IN_STORE_KEY_VALUE, false);
		return bAutoLoginIn;
	}

	public static void saveAutoLoginIn(Activity activity, boolean bAutoLoginIn) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.IS_AUTO_LOGIN_IN_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		Editor editor = sharedPreferences.edit();

		editor.putBoolean(HctConstants.IS_AUTO_LOGIN_IN_STORE_KEY_VALUE,
				bAutoLoginIn);
		editor.apply();

	}

	public static void deleteAutoLoginIn(Activity activity) {
		SharedPreferences sharedPreferences = activity.getSharedPreferences(
				HctConstants.IS_AUTO_LOGIN_IN_STORE_FILE_NAME,
				Context.MODE_WORLD_WRITEABLE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean(HctConstants.IS_AUTO_LOGIN_IN_STORE_KEY_VALUE,false);
		editor.apply();
	}

}
